functor X86Parse (S : X86_PARSE_STRUCTS) : X86_PARSE =
struct
  open S
  
  structure E2 = AsmErrorMsg
  val error = AsmErrorMsg.error
  
  structure x86LrVals = x86LrValsFun(structure Token = LrParser.Token
                                     structure Asm = Asm)
  structure Lex = x86LexFun(structure Tokens = x86LrVals.Tokens)
  structure x86P = Join(structure ParserData = x86LrVals.ParserData
		             structure Lex=Lex
		             structure LrParser = LrParser)
  exception X86ParseFailed
  
  fun parse filename =
      let (*val _ = print ("parse 1:"^filename^"\n")*)
          (* no exception should be raised here, the "Io" exception *)
          val file = TextIO.openIn filename handle Io => (raise Fail "compiler bug\n")
          (*val _ = print ("parse:"^filename^"\n")*)
	  fun get _ = TextIO.input file
	  fun parseerror(s,p1,p2) = E2.error p1 s
          (* val _ = print "lex begin:\n" *)
	  val lexer = LrParser.Stream.streamify (Lex.makeLexer get)
	  val result = #1(x86P.parse(30, lexer, parseerror, ()))
      in  result
      end handle LrParser.ParseError => (E2.anyErrors := true;
                                         raise X86ParseFailed)

               | Io => (raise X86ParseFailed)
                        
end
